package com.itboye.ihomebank.key;

import java.util.Observable;
import java.util.Observer;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ToggleButton;

import com.itboye.ihomebank.R;
import com.itboye.ihomebank.base.BaseOtherActivity;
import com.itboye.ihomebank.bean.ResultEntity;
import com.itboye.ihomebank.constants.SPContants;
import com.itboye.ihomebank.presenter.UserPresenter;
import com.itboye.ihomebank.util.ByAlert;
import com.itboye.ihomebank.util.SPUtils;

/**
 * 普通用户(锁设置)
 * 
 */
public class ActivityKeySheZhiOne extends BaseOtherActivity implements Observer {
	private ImageView close_icon;// 返回图片
	private TextView add_shap_title_tv;// 标题
	UserPresenter userPresenter;
	TextView save;
	ToggleButton shezhi_one_tb;
	private String alias;
	private String lockId;
	private String uid;
	EditText edit_name;

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.close_icon:
			finish();
			break;
		case R.id.shezhi_one_tb:

			break;
		case R.id.save:
			uid = SPUtils.get(this, null, SPContants.USER_ID, "") + "";
			if (alias.equals(edit_name.getText().toString())) {
				ByAlert.alert("当前没有做修改");
				return;
			}
			alias = edit_name.getText().toString();
			if (alias.equals("")) {
				ByAlert.alert("请输入钥匙名字");
				return;
			}
			userPresenter.updateKey("130", lockId, alias);
			break;
		default:
			break;
		}

	}

	@Override
	protected int layout_id() {
		// TODO Auto-generated method stub
		return R.layout.activity_key_shezhi_one;
	}

	@Override
	protected void onInitController() {
		// TODO Auto-generated method stub

	}

	@Override
	protected void onInit() {
		add_shap_title_tv.setText("设置");
		save.setVisibility(View.VISIBLE);
		userPresenter = new UserPresenter(this);
		lockId = getIntent().getStringExtra("lockId");
		alias = getIntent().getStringExtra("alias");
	}

	@Override
	protected void onReadIntent(Bundle bundle) {
		// TODO Auto-generated method stub

	}

	@Override
	public void update(Observable observable, Object data) {
		// TODO Auto-generated method stub
		ResultEntity entity = handlerError(data);
		if (entity != null) {
			if (entity.getEventType() == UserPresenter.updateKey_success) {
				ByAlert.alert(entity.getData());
				finish();
			} else if (entity.getEventType() == UserPresenter.updateKey_fail) {
				ByAlert.alert(entity.getData());
			}
		}
	}

}
